package com.gx.ring.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.gx.ring.dao.RingExistCorpIDInterfaceDAO;
import com.gx.ring.entity.UserServiceInfo;

public class USIInterfaceImplDAO implements RingExistCorpIDInterfaceDAO<UserServiceInfo>{
	private Connection conn = null;
	
	public USIInterfaceImplDAO(Connection conn) {
		this.conn = conn;
	}


	@Override
	public List<UserServiceInfo> queryByphNumber(String phNumber) throws SQLException {
		String sql = "SELECT * FROM ring.t_userserviceinfo WHERE PHONENUMBER=? ";
		List<UserServiceInfo> ls = new ArrayList<>();
		UserServiceInfo  usi = new UserServiceInfo();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, phNumber);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			usi = saveResult(rs);
			ls.add(usi);
		}
		rs.close();
		pst.close();
		return ls;
	}

	@Override
	public List<UserServiceInfo> queryByCorpCode(String corpCode) throws SQLException {
		String sql = "SELECT * FROM ring.t_userserviceinfo WHERE CORPCODE=? ";
		List<UserServiceInfo> ls = new ArrayList<>();
		UserServiceInfo  usi = new UserServiceInfo();
		PreparedStatement pst = conn.prepareStatement(sql);
		pst.setString(1, corpCode);
		ResultSet rs = pst.executeQuery();
		while(rs.next()){
			usi = saveResult(rs);
			ls.add(usi);
		}
		rs.close();
		pst.close();
		return ls;
	}



	@Override
	public UserServiceInfo saveResult(ResultSet rs) throws SQLException {
		UserServiceInfo  usi = new UserServiceInfo();
		usi.setLocalid(rs.getLong("LOCALID"));
		usi.setAdcalledcreatetime(rs.getTimestamp("ADCALLEDCREATETIME"));
		usi.setAdcalledoperator(rs.getLong("ADCALLEDCREATETIME"));
		usi.setAdcalledservstatus(rs.getLong("ADCALLEDSERVSTATUS"));
		usi.setAdcalledupststime(rs.getTimestamp("ADCALLEDUPSTSTIME"));
		usi.setAdcreatetime(rs.getTimestamp("ADCREATETIME"));
		usi.setAdoperator(rs.getLong("ADOPERATOR"));
		usi.setAdservstatus(rs.getLong("ADSERVSTATUS"));
		usi.setAdupstatustime(rs.getTimestamp("ADUPSTATUSTIME"));
		usi.setBand(rs.getLong("BAND"));
		usi.setBrandid(rs.getLong("BRANDID"));
		usi.setBrandmodifydate(rs.getTimestamp("BRANDMODIFYDATE"));
		usi.setCalledtonepriority(rs.getLong("CALLEDTONEPRIORITY"));
		usi.setCallercreatetime(rs.getTimestamp("CALLERCREATETIME"));
		usi.setCalleroperator(rs.getLong("CALLEROPERATOR"));
		usi.setCallerreservetime(rs.getTimestamp("CALLERRESERVETIME"));
		usi.setCallerservstatus(rs.getLong("CALLERSERVSTATUS"));
		usi.setCallerupstatustime(rs.getTimestamp("CALLERUPSTATUSTIME"));
		usi.setCallingtonepriority(rs.getLong("CALLINGTONEPRIORITY"));
		usi.setChargeflag(rs.getLong("CHARGEFLAG"));
		usi.setCopytype(rs.getLong("COPYTYPE"));
		usi.setCrbtid(rs.getLong("CRBTID"));
		usi.setCreatetime(rs.getTimestamp("CREATETIME"));
		usi.setCusttype(rs.getLong("CUSTTYPE"));
		usi.setDiscinfo(rs.getLong("DISCINFO"));
		usi.setIsarrear(rs.getLong("ISARREAR"));
		usi.setIsbgtone(rs.getLong("ISBGTONE"));
		usi.setLocalid(rs.getLong("LOCALID"));
		usi.setModeid(rs.getLong("MODEID"));
		usi.setModulecode(rs.getLong("MODULECODE"));
		usi.setMusicshowflag(rs.getLong("MUSICSHOWFLAG"));
		usi.setNetkind(rs.getLong("NETKIND"));
		usi.setOpenmodulecode(rs.getLong("OPENMODULECODE"));
		usi.setOpenoperator(rs.getLong("OPENOPERATOR"));
		usi.setOperateid(rs.getLong("OPERATEID"));
		usi.setOperator(rs.getLong("OPERATOR"));
		usi.setOperinitinfo(rs.getLong("OPERINITINFO"));
		usi.setPaykind(rs.getLong("PAYKIND"));
		usi.setPhonenumber(rs.getLong("PHONENUMBER"));
		usi.setPlayway(rs.getLong("PLAYWAY"));
		usi.setReservetime(rs.getTimestamp("RESERVETIME"));
		usi.setScpid(rs.getLong("SCPID"));
		usi.setServicetype(rs.getLong("SERVICETYPE"));
		usi.setServstatus(rs.getLong("SERVSTATUS"));
		usi.setSetpriority(rs.getLong("SETPRIORITY"));
		usi.setSubcosid(rs.getLong("SUBCOSID"));
		usi.setTotalintegral(rs.getLong("TOTALINTEGRAL"));
		usi.setUpstatustime(rs.getTimestamp("UPSTATUSTIME"));
		usi.setUsergroup(rs.getLong("USERGROUP"));
		usi.setUserplatformtype(rs.getLong("USERPLATFORMTYPE"));
		usi.setUserservid(rs.getLong("USERSERVID"));
		return usi;
	}



	
	

}
